#!/bin/bash

# Git 推送脚本

echo "🚀 准备推送代码到 Gitee..."

# 检查是否有未暂存的更改
if ! git diff-index --quiet HEAD --; then
    echo "📝 发现未暂存的更改，正在添加..."
    git add .
fi

# 检查是否有暂存的更改需要提交
if ! git diff-index --quiet --cached HEAD --; then
    echo "💬 请输入提交信息:"
    read -r commit_message
    
    if [ -z "$commit_message" ]; then
        commit_message="Update: $(date +'%Y-%m-%d %H:%M:%S')"
    fi
    
    echo "📦 提交更改: $commit_message"
    git commit -m "$commit_message"
else
    echo "ℹ️  没有需要提交的更改"
fi

# 推送到远程仓库
echo "📤 推送到 Gitee..."
git push origin master

if [ $? -eq 0 ]; then
    echo "✅ 推送成功！"
    echo "🔗 仓库地址: https://gitee.com/karonluo/node-cotong-ys2u8-login"
else
    echo "❌ 推送失败，可能需要认证或检查网络连接"
    echo "💡 提示:"
    echo "   1. 确保已配置 Gitee 认证"
    echo "   2. 检查仓库是否存在"
    echo "   3. 检查网络连接"
fi
